<template>
  <wd-form-item
    v-if="
      typeof props.component.display == 'undefined' ||
      props.component.display === true
    "
    :component="props.component"
    :custom-field="props.customField"
  >
      <wd-wang-editor v-model="value"></wd-wang-editor>
  </wd-form-item>
</template>

<script setup>
import { ref, inject, onMounted, watch } from "vue";
import { get, set } from "lodash";
import WdWangEditor from "@cwd/widgets/wd-wang-editor/index.vue";


const props = defineProps({
  component: Object,
  customField: { type: String, default: undefined },
});

const formModel = inject("formModel");
const index = props.customField ?? props.component.dataIndex;
const value = ref(get(formModel.value, index));

watch(
  () => get(formModel.value, index),
  (vl) => (value.value = vl)
);
watch( () => value.value, v => {
  set(formModel.value, index, v)
  index.indexOf('.') > -1 && delete formModel.value[index]
} )
</script>